﻿using System.Linq;
using Hangfire;
using Microsoft.Extensions.Options;
using JESAI.Core.DependencyInjection;
using JESAI.Schedule.HangFire.Abstrctions.BackgroundJobs;

namespace JESAI.Schedule.HangFire.BackgroundJobs.Hangfire;

public class DashboardOptionsProvider : ITransientDependency
{
    protected BackgroundJobOptions _backgroundJobOptions { get; }

    public DashboardOptionsProvider(IOptions<BackgroundJobOptions> backgroundJobOptions)
    {
        _backgroundJobOptions = backgroundJobOptions.Value;
    }

    public virtual DashboardOptions Get()
    {
        return new DashboardOptions
        {
            DisplayNameFunc = (dashboardContext, job) =>
                _backgroundJobOptions.GetJob(job.Args.First().GetType()).JobName
        };
    }
}
